import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import { query2obj } from '@feidao/core/querystring';
import client_login from '@feidao/web/atom/browser/msg/user-login';
import put_info from '@feidao/web/atom/browser/storage/put';



export default async function a001(fd: IFeidaoAiBrowserComponent, ...args: any[]) {	//获取错误提示标签，并添加默认隐藏属性
	const unamee = document.getElementById('unamee');
	const upwde = document.getElementById('upwde');
	unamee.classList.add('display-n');
	upwde.classList.add('display-n');
	//获取账号密码
	const name = document.querySelector<HTMLInputElement>('#uname').value;
	const pwd = document.querySelector<HTMLInputElement>('#upwd').value;
	try {
		//调用登录通用服务
		const res = await client_login(fd.data.spaceid, name, pwd);
		//存储用户信息



		put_info('user_name', res.user_name);
		put_info('user_code', res.usercode);
		//跳转其他页面
		const backurl = fd.data.params.backurl;
		if (backurl) {
			window.location.href = backurl;
		} else {
			window.location.href = 'index.html';
		}
	} catch (error) {
		//登陆错误信息
		console.log("error", error);
		if (error === "用户名错误,请您重新输入") {
			console.log("aaaa");
			unamee.classList.remove('display-n');
			setTimeout(function () { document.getElementById("unamee").className += ' display-n'; }, 2000);
		} else {
			upwde.classList.remove('display-n');
			setTimeout(function () { document.getElementById("upwde").className += ' display-n'; }, 2000);
		}
	}
}
